HAL SMARTCARD migration: List of applicable concepts

This section provides information about the HAL SMARTCARD applicable architecture concepts.

Concepts for SMARTCARD

Concept

Description

Separation of initialization and configuration functions

The initialization has been split into separate init and config functions:

  • HAL_SMARTCARD_Init(): initializes the handle and links it to a USART instance.

  • HAL_SMARTCARD_SetConfig(): sets the basic configuration to enable the use of the USART peripheral.

Removal and conversion of init structure to configuration structure

The init structure SMARTCARD_InitTypeDef has been removed from the handle.

Renaming of the handle structure

The handle structure has been renamed to hal_smartcard_handle_t.

Renaming unitary init structures

The structure SMARTCARD_InitTypeDef is no longer available and has been replaced by hal_smartcard_config_t.

Remove MspInit and MspDeInit callbacks

hal_SMARTCARD_MspInit() and hal_SMARTCARD_MspDeInit() are no longer available and have been replaced by a usersequence to initialize and configure the SMARTCARD.

Unitary configuration APIs

New APIs are available to get and set SMARTCARD features.

Dedicated DMA link APIs replace generic __HAL_LINKDMA macro

The __HAL_LINKDMA macro is replaced by new functions HAL_SMARTCARD_SetTxDMA() and HAL_SMARTCARD_SetRxDMA() to link a SMARTCARD HAL handle to a DMA HAL handle.

Introduction of HAL user data set/get APIs

Two functions to set/get user data are available: HAL_SMARTCARD_SetUserData() and HAL_SMARTCARD_GetUserData().

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each SMARTCARD event. These functions are used to register callback functions for different SMARTCARD events.

HAL implementation with LL inline functions

HAL SMARTCARD APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL SMARTCARD define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL SMARTCARD driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

The SMARTCARD Driver uses a state machine to manage its operations. The states are :

  • HAL_SMARTCARD_STATE_RESET

  • HAL_SMARTCARD_STATE_INIT

  • HAL_SMARTCARD_STATE_IDLE

  • HAL_SMARTCARD_STATE_RX_ACTIVE

  • HAL_SMARTCARD_STATE_TX_ACTIVE

  • HAL_SMARTCARD_STATE_ABORT

Revised and optimized HAL API status returns

Update HAL SMARTCARD were updated to return:

  • HAL_INVALID_PARAM: in case of NULL p_config structure pointer.

  • HAL_ERROR: in case of an error .

  • HAL_BUSY: in case of an ongoing process.

  • HAL_TIMEOUT: in case of user timeout

  • HAL_OK: in case of a successfully completed operation

Revised and optimized HAL error management

The HAL error handling mechanisms have been redesigned to improve the detection, reporting, and handling of errors. This rework aims to provide more detailed and consistent error information such as HAL_SMARTCARD_ERROR_PE and HAL_SMARTCARD_ERROR_ORE.

New APIs for filtering optional asynchronous process interrupts

New HAL SMARTCARD Transmit APIs with interrupt filtering capability, such as HAL_SMARTCARD_Transmit_IT_Opt() and HAL_SMARTCARD_Transmit_DMA_Opt().

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL SMARTCARD driver have been removed and replaced by _t.

Replaced multi-line macros with inline functions

For the HAL SMARTCARD driver, large macros have been replaced by inline functions to maintain code consistency, improve readability, and benefit from compiler optimization. Inline functions also offer better support for debugging and strict type management, reducing the risk of errors.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The parameters and state are checked using ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros.

Merge HAL extension files with common ones and remove the EX prefix from APIs.

Only one HAL SMARTCARD header file remains and all macros, define statements, and functions from hal_smartcard_ex.h have been moved to hal_smartcard.h.

Provide RTOS-compatible acquire/release bus services for communication peripheral drivers.

New HAL_SMARTCARD_AcquireBus() and HAL_SMARTCARD_ReleaseBus() functions are provided, allowing the acquisition and release of a HAL SMARTCARD handle to protect a full sequence.

Add HAL PPP Services for Drivers with Handle to Retrieve Corresponding Peripheral Clock Frequency.

HAL SMARTCARD Driver provides a new API to retrieve clock frequency: HAL_SMARTCARD_GetClockFreq().

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including SMARTCARD instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL SMARTCARD functions start with HAL_SMARTCARD.